﻿using System.Collections.Generic;
using Bingosoft.Data;
using Bingosoft.RestService.Attributes;
using System.Data;

namespace Bingosoft.Modules.DataDictionary
{
    [Service("DeliveredService")]
    public class DeliveredService
    {
        private readonly Dao dao = Dao.Get();

        public void DeleteDataItem(string Id)
        {
            IDictionary<string, object> dictionary = new Dictionary<string, object> { { "Id", Id } };
            dao.ExecuteNonQuery("Delivered.delete", dictionary);
        }

        public DataSet GetInfo(string type, string id)
        {
            string tableName = "";
            switch (type)
            {
                case "1":
                    tableName = "NewMaterial";
                    break;
                case "2":
                    tableName = "GoodMaterial";
                    break;
                case "3":
                    tableName = "RepairMaterial";
                    break;
                case "4":
                    tableName = "MaterialsModel";
                    break;
                default:
                    break;
            }
            string sql = "SELECT "
                         +" t1.MaterialsNo AS MaterialsNo"
                         +" ,t1.MaterialsName AS MaterialsName"
                         +",t1.MaterialsModel AS MaterialsModel  "
                         +" FROM "+tableName+" t1 WITH(NOLOCK) "
                         +" WHERE 1=1"
                         +" AND t1.ID=@ID";
             IDictionary<string, object> dictionary = new Dictionary<string, object> {{"Type", type},{"ID",id}};
             return dao.QueryDataSet(sql, dictionary);
        }

        public DataSet GetEditInfo(string d_ID)
        {
            string sql = @"SELECT t0.ForeignD,t0.Type FROM dbo.Delivered t0
                            where t0.ID=@ID";
            IDictionary<string, object> dictionary = new Dictionary<string, object> { { "ID", d_ID } };
            return dao.QueryDataSet(sql, dictionary);
        
        }
    }
}